<template>
  <div>
    <!--头部-->
    <div class="front-header">
      <div class="front-header-title">
<!--        <img src="@/assets/imgs/logo.png" style="width: 30px;height: 30px;" alt="">-->
        <div class="title-name">系统</div>
      </div>

        <div class="front-header-nav">
          <el-menu :default-active="$route.path" mode="horizontal" router>
						<el-menu-item index="/front/index" class="el-menu-nav" >首页</el-menu-item>
            <el-menu-item index="/front/merchant" class="el-menu-nav" >店铺信息</el-menu-item>
            <el-menu-item index="/front/pet" class="el-menu-nav" >我的宠物</el-menu-item>
            <el-menu-item index="/front/fosterOrder" class="el-menu-nav" >寄养订单</el-menu-item>
						<el-menu-item index="/front/notice" class="el-menu-nav">系统公告</el-menu-item>
          </el-menu>
        </div>
      <div class="front-header-info">
        <div v-if="!user.username">
          <el-button @click="$router.push('/login')">登录</el-button>
          <el-button @click="$router.push('/register')">注册</el-button>
        </div>
        <div v-else>
          <el-dropdown size="medium">
            <div class="front-header-dropdown">
              <img :src="user.avatar" alt="">
              <div class="front-header-div">
                <span>{{ user.name }}</span><i class="el-icon-arrow-down" ></i>
              </div>
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="ToUserInfo">个人中心</el-dropdown-item>
              <el-dropdown-item @click.native="ToChangePassword">修改密码</el-dropdown-item>
              <el-dropdown-item>
                <div @click="logout">退出</div>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>
    <!--主体-->
    <div class="main-body">
      <router-view ref="child" @update:user="updateUser" />
    </div>
  </div>

</template>

<script>

export default {
  name: "FrontLayout",

  data () {
    return {
      top: '',

      user: JSON.parse(localStorage.getItem("userInfo") || '{}'),
    }
  },

  mounted() {

  },
  methods: {

    updateUser() {
      this.user = JSON.parse(localStorage.getItem('userInfo') || '{}')   // 重新获取下用户的最新信息
    },
    ToUserInfo() {
        this.$router.push('/front/UserInfo')
    },
    ToChangePassword() {
        this.$router.push('/front/Password')
    },
    // 退出登录
    logout() {
      localStorage.removeItem("userInfo");
      this.$router.push("/login");
    },
  }

}
</script>

<style scoped>
@import "@/assets/css/front.css";
</style>